package cn.mayday.algorithms.year2021.month1.暂未归类;

/**
 * 字符串左旋转
 *
 * @author Mayday05
 * @date 2021/5/12 11:27
 */
public class Offer058IIReverseLeftWords {

    public static void main(String[] args) {
        String input = "abcdefg";
        int k = 2;
        String result = new Offer058IIReverseLeftWords().reverseLeftWords(input, k);
        System.out.println("result == " + result);
    }

    /**
     * 字符串左旋转
     * <p>
     * 方法一：暴力拆分 时间复杂度N，空间复杂度N
     *
     * @param s 指定字符串
     * @param n 指定旋转位置
     * @return
     */
    public String reverseLeftWords(String s, int n) {

        StringBuilder result = new StringBuilder();

        for (int i = n; i < s.length(); i++) {
            result.append(s.charAt(i));
        }
        for (int i = 0; i < n; i++) {
            result.append(s.charAt(i));
        }
        return result.toString();
    }


}
